Method delegation with less boilerplate
This crate removes some boilerplate for structs that simply delegate some of their methods to one or more of their fields.
It gives you the delegate!
macro, which delegates method calls to selected expressions (usually inner fields).
Example:
A Stack data structure implemented using an inner Vec via delegation.
use delegate;
Features:
- Delegate to a method with a different name
- Use an arbitrary inner field expression
- Change the return type of the delegated method using a
From
impl or omit it altogether
;
- Call
await
on async functions
;
You can use the #[await(true/false)]
attribute on delegated methods to specify if .await
should
be generated after the delegated expression. It will be generated by default if the delegated
method is async
.
- Delegate to multiple fields
- Inserts
#[inline(always)]
automatically (unless you specify#[inline]
manually on the method) - Specify expressions in the signature that will be used as delegated arguments
use delegate;
;
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Conduct
Please follow the Rust Code of Conduct. For escalation or moderation issues
please contact the crate author(s) listed in Cargo.toml
.